'''
使用HTTPError进行异常检测
'''
from urllib.request import urlopen
from urllib.error import HTTPError
from bs4 import BeautifulSoup

try:
    # html = urlopen("https://luxuewen.com/lauwen/ind1ex.html")
    html = urlopen("https://luxuewen.com/lauwen/index.html")
except HTTPError as e:
    print(e)
else:
    bsObj = BeautifulSoup(html.read(), "html.parser")
    print(bsObj.p)
